<?php
namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;

class Subscribe extends NotORM {
	/* 预约数量 */
	public function getSubscribeNums($uid) {
		
        $nowtime=time();
        
        $addtime=$nowtime- 60*60*24;
        
		$list=\PhalApi\DI()->notorm->subscribe
					->select("*")
					->where('(liveuid=? or uid=?) and addtime>=?',$uid,$uid,$addtime)
					->count();

		return (string)$list;

	}

	/* 预约我的 */
	public function getTome($uid,$p) {
		
        if($p<1){
            $p=1;
        }
		$pnum=50;
		$start=($p-1)*$pnum;
        
        $nowtime=time();
        
        $addtime=$nowtime- 60*60*24;
        
		$list=\PhalApi\DI()->notorm->subscribe
					->select("*")
					->where('liveuid=? and addtime>=?',$uid,$addtime)
					->limit($start,$pnum)
                    ->order('id desc')
					->fetchAll();

		return $list;

	}

	/* 我预约的 */
	public function getMeto($uid,$p) {
		
        if($p<1){
            $p=1;
        }
		$pnum=50;
		$start=($p-1)*$pnum;
        
        $nowtime=time();
        
        $addtime=$nowtime- 60*60*24;
        
		$list=\PhalApi\DI()->notorm->subscribe
					->select("*")
					->where('uid=? and addtime>=?',$uid,$addtime)
					->limit($start,$pnum)
                    ->order('id desc')
					->fetchAll();

		return $list;

	}

	/* 删除过期预约 */
	public function delOverdue() {
		
        $nowtime=time();
        
        $addtime=$nowtime - 60*60*24;
        
		$rs=\PhalApi\DI()->notorm->subscribe
					->where('addtime<?',$addtime)
					->delete();

		return $rs;

	}
    	
	/* 我预约的 */
	public function setSubscribe($data) {
		
		$rs=\PhalApi\DI()->notorm->subscribe
					->insert($data);

		return $rs;

	}

	/* 预约信息 */
	public function getSubscribe($id) {
		
		$info=\PhalApi\DI()->notorm->subscribe
                    ->select('*')
                    ->where('id=?',$id)
					->fetchOne();

		return $info;

	}

	/* 删除预约 */
	public function delSubscribe($id) {
		
		$rs=\PhalApi\DI()->notorm->subscribe
                    ->where('id=?',$id)
					->delete();

		return $rs;

	}

	/* 修改状态 */
	public function setStatus($id,$status) {
		
		$rs=\PhalApi\DI()->notorm->subscribe
                    ->where('id=?',$id)
					->update( ['status'=>$status] );

		return $rs;

	}
}
